package com.example.archermind.myapplication;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AddNotificationActivity extends BaseActivity {


    @BindView(R.id.et_title)
    EditText etTitle;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.et_icon)
    EditText etIcon;
    @BindView(R.id.et_notificationid)
    EditText etNotificationid;
    @BindView(R.id.et_packageName)
    EditText etPackageName;
    @BindView(R.id.et_priority)
    EditText etPriority;
    @BindView(R.id.cb_isAction)
    CheckBox cbIsAction;
    @BindView(R.id.btn_addNotification)
    Button btnAddNotification;
    @BindView(R.id.tv_onClickNotification)
    TextView tvOnClickNotification;
    @BindView(R.id.tv_onDelNotification)
    TextView tvOnDelNotification;

    Handler mHdler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle bundle = msg.getData();
            String notificationid = bundle.getString("notificationid");
            switch (msg.what) {
                case NOTIFICATIONCALLBACK + 0:
                    tvOnClickNotification.setText("OnClickNotification notificationid:"+notificationid);
                    break;
                case NOTIFICATIONCALLBACK + 1:
                    tvOnDelNotification.setText("OnDelNotification notificationid:"+notificationid);
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_notification);
        unbinder = ButterKnife.bind(this);
        setHandler(mHdler);

    }

    @OnClick(R.id.btn_addNotification)
    public void onViewClicked(View view) {
        try {
            String title = etTitle.getText().toString();
            String content = etContent.getText().toString();
            String icon = etIcon.getText().toString();
            String notificationid = etNotificationid.getText().toString();
            String packagename = etPackageName.getText().toString();
            int priority = Integer.parseInt(etPriority.getText().toString());
            boolean isAction = cbIsAction.isChecked();

            Log.d(TAG, "title:" + title + " content:" + content + " icon:" + icon + " notificationid:" + notificationid + " packagename:" + packagename + " priority:" + priority + " isAction" + isAction);
            getNotificationService().addNotification(title, content, icon, notificationid, packagename, priority, isAction);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.d(TAG, "add notification");
    }


}
